<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>websocket测试页</title>
</head>
<body>
测试WebSocket：
<br/>
token:<input type="text" id="token" value="test"/>
<br/>
<br/>
<input type="button" onclick="openWebSocket()" value="打开WebSocket"/>
<br/>
<br/>
<input type="button" onclick="openSubscribeQuotation()" value="打开订阅行情"/>
<input type="button" onclick="closeSubscribeQuotation()" value="关闭订阅行情"/>
</body>
<script type="text/javascript">
function openSubscribeQuotation() {
	if (ws) {
		ws.send("{\"type\": \"subscribe\", \"subscribeQuotation\":1}");
	}
}
function closeSubscribeQuotation() {
	if (ws) {
		ws.send("{\"type\": \"subscribe\", \"subscribeQuotation\":0}");
	}
}
var ws = undefined;
function openWebSocket() {
	var token = document.getElementById("token").value;

	//打开一个 web socket
	ws = new WebSocket("ws://localhost:8230/websocket?token=" + token);
	ws.onopen = function() {
	    // Web Socket 已连接上，使用 send() 方法发送数据
	    ws.send("测试发送");
	    console.log('open');
	};
	ws.onmessage = function (e) { 
	    console.log('message', e.data);
	};
	ws.onclose = function() { 
	    console.log('close');
	};
}
</script>
</html>